<script>
var bivariateIndex;

function showLensBivariate(entry_id, goods_id, middle_id, ranges) {
	var url = '{{urlfor "ErpEntryController.LensBivariate"}}?entry_id='+entry_id + '&middle_id='+ middle_id +'&goods_id='+goods_id+'&ranges='+encodeURIComponent(ranges);
	bivariateIndex = layer.open({
		type: 2,
		title: '光度二维表',
		shadeClose: false,
		shade: 0.2,
		maxmin: true,
		shift: 1,
		area: ['100%', '100%'],
		content: url
	});
}
//光学镜架
function showMountingAdd(entry_id, goods_id, middle_id){
	var url = '{{urlfor "ErpEntryController.MountingAdd"}}?entry_id='+entry_id + '&middle_id='+ middle_id +'&goods_id='+goods_id;
	var title = '采购明细';
	layer.open({
		type: 2,
		title: title,
		shadeClose: false,
		shade: 0.2,
		maxmin: true,
		shift: 1,
		area: ['80%', '70%'],
		content: url
	});
}

//其它
function showOtherAdd(entry_id, goods_id, middle_id){
	var url = '{{urlfor "ErpEntryController.OtherAdd"}}?entry_id='+entry_id + '&middle_id='+ middle_id +'&goods_id='+goods_id;
	var title = '采购明细';
	layer.open({
		type: 2,
		title: title,
		shadeClose: false,
		shade: 0.2,
		maxmin: true,
		shift: 1,
		area: ['600px', '40%'],
		content: url
	});
}

//药品
function showDrugsAdd(entry_id, goods_id, middle_id){
    var url = '{{urlfor "ErpEntryController.DrugsAdd"}}?entry_id='+entry_id + '&middle_id='+ middle_id +'&goods_id='+goods_id;
    var title = '采购明细';
    layer.open({
        type: 2,
        title: title,
        shadeClose: false,
        shade: 0.2,
        maxmin: true,
        shift: 1,
        area: ['80%', '70%'],
        content: url
    });
}

function closeLensBivariate() {
	layer.close(bivariateIndex);
}
function closeSelectComplete() {
	layer.closeAll();
	$.post('{{ urlfor "ErpEntryController.GetMiddleData" }}', {'entry_id':'{{.m.Id}}'}, function(res){
		if(res.code == 0) {
			$('#goods-list').html('');
			$.each(res.data, function(index, value){
				var html = '<div class="list am-cf">\
                        <div class="am-text-sm am-u-sm-10"><i class="am-icon-file-text"></i>&nbsp;&nbsp;&nbsp;'+ productGroupName(value.Products) +'</div>\
                        <div class="am-text-sm am-u-sm-2 am-text-center">采购数量<br />'+ value.PurchaseNum +' <br /><a href="#" data-entry="'+ value.EntryId +'" data-goods="'+ value.Products.Id +'" data-attr="'+ encodeURIComponent(value.Attribute) +'" data-id="'+ value.Id +'" data-typeid="'+ value.Products.TypeId +'" onclick="editMiddleData(this);return false;" class="am-text-xs">编辑</a></div>\
                    </div>';
					
				$('#goods-list').append(html);	
			});
		}
	}, 'json');
	
}

function editMiddleData(h) {
	var o = $(h);
	var typeid = o.data('typeid');
	var entry_id = o.data('entry');
	var goods_id = o.data('goods');
	var attr = o.data('attr');
	var middle_id = o.data('id');

	switch(typeid) {
		case 10:
			showLensBivariate(entry_id, goods_id, middle_id, decodeURIComponent(attr));
			break;
		case 20:
			showLensBivariate(entry_id, goods_id, middle_id, decodeURIComponent(attr));
			break;
		case 30:
			showMountingAdd(entry_id, goods_id, middle_id);
			break;
		case 40:
			showLensBivariate(entry_id, goods_id, middle_id, decodeURIComponent(attr));
			break;	
		case 41:
			showMountingAdd(entry_id, goods_id, middle_id);
			break;	
		case 50:
			showOtherAdd(entry_id, goods_id, middle_id);
			break;	
		case 60:
			showOtherAdd(entry_id, goods_id, middle_id);
			break;		
		case 70:
            showOtherAdd(entry_id, goods_id, middle_id);
			break;		
							
	}
}

closeSelectComplete();

//驳回
$('#cennelBtn').click(function(){
    var entry_id = '{{.m.Id}}';
    $.post('{{ urlfor "ErpEntryController.SaveAuditing" }}', {'entry_id':entry_id, 'status':2}, function(res) {
        if(res.code == 1) {
            layer.alert(res.msg);
            return false;
        }
        location = '{{ urlfor "ErpEntryController.Index" }}';
    },'json');

});

//通过
$('#yesBtn').click(function(){
    var entry_id = '{{.m.Id}}';
    $.post('{{ urlfor "ErpEntryController.SaveAuditing" }}', {'entry_id':entry_id, 'status':1}, function(res) {
        if(res.code == 1) {
            layer.alert(res.msg);
            return false;
        }
        location = '{{ urlfor "ErpEntryController.Index" }}';
    },'json');

});

</script>